import { Component } from 'react';

import { Boxs, Toast } from 'saltui';

const { Box,VBox } = Boxs;

import './PageHome.less';
import DB from '../../../app/db';
import { errorIcon, successIcon } from '../../../app/variables';


export default class Page extends Component {
  constructor(props) {
    super(props);
    var applyRecordId = this.props.params.id;
    
    //关闭加载页的遮罩效果
    $(".loading-containter").hide();
    //禁用ios弹性事件
    dd.ui.webViewBounce.disable();

    this.state = {
      applyRecordId: applyRecordId,
      isSuccess: false,
      type: '0',
      msg: ""
    }
  }

  componentWillMount() {
    let t = this;
    var thirdMenuType = getLoginUserInfo().thirdMenuType;
    var page_title = "扫码签到";
    $("title").text(page_title);
    if(thirdMenuType == 'DING'){
      dd.biz.navigation.setTitle({
        title : page_title,//控制标题文本，空字符串表示显示默认文本
        onSuccess : function(result) {
        },
        onFail : function(err) {}
      });
    }else if(thirdMenuType =='MH'){
      !!emp&&emp.window.setTitle({
        title: {
            text: page_title,
            icon: '',
            actionmenu: {}
        },
      });
    }
    let param = {id: t.state.applyRecordId, signType: "0"};
    DB.SomeModuleAPI.userSigned(param).then((content) => {
      //不可以签到
      var isSuccess = false;
      var msg = "";
      var status = content.status;
      //alert(status);
      if(status == "1"){
        msg = "未到签到时间";
      }else if(status == "0"){//成功签到
        isSuccess = true;
        msg = "签到成功";
      }else if(status == "2"){//会议结束
        msg = "会议已结束";
      }else if(status == "3"){
        msg = "会议已取消";
      }else if(status == "-1"){
        msg = "您未参加当前会议";
      }

      t.setState({
        isSuccess: isSuccess,
        type: '1',
        msg: msg
      });
      //返回至列表页面
      setTimeout(function(){
        if(thirdMenuType=="DING"){
          dd.biz.navigation.goBack();
        }else if(thirdMenuType=="WX"){
          history.back();
        }else if(thirdMenuType=="MH"){
          !!emp&&emp.navigateBack();
        }else{
          history.back();
        }
      },2000);
    }).catch((error) => {
      if(typeof(error.errorMsg) == 'undefined'){
        Toast.show({
          type: 'error',
          content: '提交出错'
        });
      }else{
        Toast.show({
        type: 'error',
        content: error.errorMsg
         });
      }
    });
  }

  render() {
    return (
        <div className="signin-wrapper ">
            <VBox vAlign="center" hAlign="center" className="signin">
                <Box>
                  <div>
                     <img src={this.state.type=='0' ? '' : (this.state.isSuccess ? successIcon : errorIcon) } alt="" style={{width: 160 + 'px'}}/>
                   </div>
                </Box>
                <div className="t-H30"></div>
                <Box className={ this.state.isSuccess ? 't-FCc t-FS20 t-FCgreen' : 't-FCc t-FS20 t-FCred' }> 
                   { this.state.msg }
                </Box>
            </VBox>
        </div>    
    );
  }
}
